﻿//----------------------------------------------------

#region 命名空间

//    版权：
//    作者：
//建立时间：2012-09-11 00:00:33
//    描述：
//----------------------------------------------------
using System;
using System.Data;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Web.UI;
using WinnerCMS.Data;
using WinnerCMS.Model;
using WinnerCMS.Common;

#endregion

namespace WinnerCMS.BLL
{
    /// <summary>
    /// 业务逻辑类 WinnerCMS_VoteChoice 的摘要说明。
    /// </summary>
    public class VoteChoiceManage
    {
        private static readonly VoteChoiceDal Dal = new VoteChoiceDal();

        #region 添加

        /// <summary>
        /// 添加
        /// </summary>
        [Logging("添加投票选项。"), ExceptionCall]
        public Result Add(VoteChoice model)
        {
            Result res = new Result();
            if (model.Id == 0)
            {
                model.OrderId = 0;
                Dal.Add(model);
            }
            else
            {
                Dal.Edit(model);
            }
            return res;
        }

        #endregion

        #region 删除

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Logging("删除投票选项。"), ExceptionCall]
        public Result Delete(string id)
        {
            Result res = new Result();
            if (string.IsNullOrEmpty(id))
            {
                res.Errors = "至少选择一项。";
            }
            else
            {
                Dal.Delete(int.Parse(id));
            }
            return res;
        }

        #endregion

        #region 加载数据

        /// <summary>
        /// 加载数据
        /// </summary>
        public VoteChoice GetInfo(string id)
        {
            return Dal.GetInfo(int.Parse(id));
        }

        #endregion

        #region 加载投票项目

        /// <summary>
        /// 加载投票项目
        /// </summary>
        /// <param name="voteId"></param>
        /// <returns></returns>
        public IList<VoteChoice> ForVoteLoad(int voteId)
        {
            return Dal.ForVoteLoad(voteId);
        }

        /// <summary>
        /// 加载投票项目
        /// </summary>
        /// <param name="voteId"></param>
        /// <param name="ac"></param>
        /// <returns></returns>
        public VoteChoice ForVoteLoad(string voteId, Action<IList<VoteChoice>> ac)
        {
            IList<VoteChoice> list = Dal.ForVoteLoad(int.Parse(voteId));
            if (!list.Any())
            {
                return null;
            }
            if (ac != null)
            {
                ac(list);
            }

            return list[0];
        }

        #endregion
    }
}